package com.ythook.mentor.controller;

import com.ythook.mentor.entity.MentorCalendar;
import com.ythook.mentor.entity.MentorSkills;
import com.ythook.mentor.entity.Technologies;
import com.ythook.mentor.service.MentorCalendarService;
import com.ythook.mentor.service.MentorSkillsService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;

@Controller
@RequestMapping("/api")
public class MentorCalendarController {
    @Resource
    private MentorCalendarService mentorCalendarService;
    private Logger logger = LoggerFactory.getLogger(MentorCalendarController.class);

    @GetMapping("/calendar")
    public ResponseEntity<List<MentorCalendar>> search() {
        return ResponseEntity.ok(mentorCalendarService.search());
    }
    @GetMapping("/calendar/findById/{id}")
    public ResponseEntity<MentorCalendar> findById(@PathVariable("id") Long id) {
        return ResponseEntity.ok(mentorCalendarService.findById(id).orElse(new MentorCalendar()));
    }

    @GetMapping("/calendar/findByMentorId/{id}")
    public ResponseEntity<Optional<MentorCalendar>> findByMentorId(@PathVariable("id") Long id) {
        return ResponseEntity.ok(mentorCalendarService.findByMentorId(id));
    }

    @DeleteMapping("/calendar/delete/{id}")
    public ResponseEntity<Object> delete(@PathVariable("id") Long id){
        mentorCalendarService.delete(id);
        Map<String,Object> map = new HashMap<>();
        map.put("status","success");
        return ResponseEntity.ok(map);
    }

    @PostMapping("/calendar/add")
    public ResponseEntity<HttpStatus> add(@RequestBody MentorCalendar mentorCalendar){
        mentorCalendarService.add(mentorCalendar);
        return ResponseEntity.ok(HttpStatus.CREATED);
    }

    @PutMapping("/calendar/update")
    public ResponseEntity<Object> update(@RequestBody MentorCalendar mentorCalendar){
        Map<String,Object> map = new HashMap<>();
        map.put("status","success");
        map.put("data", mentorCalendarService.update(mentorCalendar));
        return ResponseEntity.ok(map);
    }
}
